<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="时间" prop="monthPicker">
        <el-date-picker
          v-model="queryParams.monthPicker"
          value-format="YYYY-MM"
          type="month"
          placeholder="选择时间"
          clearable
          class="!w-240px"
          @change="handleMonthChange"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      
      <el-table-column label="年份" align="center" prop="years" />
      <el-table-column label="月份" align="center" prop="month" />
      <el-table-column label="员工姓名" align="center" prop="userName" />
      
      <el-table-column label="分配企业总户数" align="center" prop="totalEnterprises" />
      <el-table-column label="小规模户数" align="center" prop="smallScaleEnterprises" />
      <el-table-column label="一般纳税人户数" align="center" prop="generalTaxpayerEnterprises" />
      <el-table-column label="小规模分" align="center" prop="smallScaleScore" />
      <el-table-column label="一般纳税人分" align="center" prop="generalTaxpayerScore" />
      <el-table-column label="简化小规模户数" align="center" prop="simplifiedSmallScale" />
      <el-table-column label="简化一般纳税人户数" align="center" prop="simplifiedGeneralTaxpayer" />
      <el-table-column label="简化小规模分" align="center" prop="simplifiedSmallScaleScore" />
      <el-table-column label="简化一般纳税人分" align="center" prop="simplifiedGeneralTaxpayerScore" />
      <el-table-column label="开票分" align="center" prop="invoiceScore" />
      <el-table-column label="特殊分" align="center" prop="specialScore" />
      <el-table-column label="工龄分" align="center" prop="seniorityScore" />
      <el-table-column label="证书分" align="center" prop="certificateScore" />
      <el-table-column label="收款完成率(%)" align="center" prop="collectionCompletionRate" />
      <el-table-column label="收款扣分" align="center" prop="collectionDeduction" />
      <el-table-column label="投诉扣分" align="center" prop="complaintDeduction" />
      <el-table-column label="流失扣分" align="center" prop="lossDeduction" />
      <el-table-column label="记账扣分" align="center" prop="accountingDeduction" />
      <el-table-column label="其他扣分" align="center" prop="otherDeduction" />
      <el-table-column label="工作绩效考核扣分小计" align="center" prop="performanceDeductionSubtotal" />
      <el-table-column label="负责人给予考核分" align="center" prop="managerAssessmentScore" />
      <el-table-column label="总分值" align="center" prop="totalScore" />
      <el-table-column label="考核工资" align="center" prop="assessmentSalary" />
      <el-table-column label="考核基数" align="center" prop="otherAdjustment" />
      <el-table-column label="状态" align="center" prop="status">
        <template #default="scope">
          <el-tag :type="scope.row.status === 1 ? 'success' : 'warning'">
            {{ scope.row.status === 1 ? '已发布' : '未发布' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
</template>

<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import { EmployeeScoreApi, EmployeeScoreVO } from '@/api/oa/employeescore'

/** 个人分值考核 列表 */
defineOptions({ name: 'MyEmployeeScore' })

const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref<EmployeeScoreVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  years: undefined as string | undefined,
  month: undefined as string | undefined,
  monthPicker: undefined as string | undefined, // 用于界面显示的月份选择器
  status: 1
})
const queryFormRef = ref() // 搜索的表单

/** 月份选择器变化处理 */
const handleMonthChange = (value: string | null) => {
  if (value) {
    // 拆分年月数据,例如 "2024-03" -> years: "2024", month: "03"
    const parts = value.split('-')
    queryParams.years = parts[0]
    queryParams.month = parts[1]
  } else {
    // 清空时重置年份和月份
    queryParams.years = undefined
    queryParams.month = undefined
  }
}
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await EmployeeScoreApi.getMyEmployeeScorePage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
  